public class test3_2 {
    public static void main(String[] args) {
        int n = 20000;
        boolean[] primes = new boolean[n + 1];

        // 初始化：所有数先标记为素数
        for (int i = 2; i <= n; i++) {
            primes[i] = true;
        }

        // 筛法过程
        for (int i = 2; i * i <= n; i++) {
            if (primes[i]) {
                for (int j = i * i; j <= n; j += i) {
                    primes[j] = false;
                }
            }
        }

        // 输出结果
        int cnt = 0;
        for (int i = 2; i <= n; i++) {
            if (primes[i]) {
                cnt++;
                System.out.print(i + " ");
                if (cnt % 5 == 0) {
                    System.out.println();
                }
            }
        }
    }
}
